package Writers;

import java.io.*;
import java.text.*;
import java.util.*;

import Readers.InputsReader;

    public class MsgLog {
    	protected static String defaultLogFile = System.getProperty("user.dir")+"\\results.txt ";
    	protected static String initialsLogFile = System.getProperty("user.dir")+"\\init.txt";
    	
        public static void write_to_init(String s) throws Exception{	    
				try {
					write(initialsLogFile, s +  "\n", false);
				} catch (IOException e1) {
					e1.printStackTrace();
				}
		}
		
        
        
        public static void write_to_log(String s) throws Exception{
		    try {
				//write(defaultLogFile+ InputsReader.getLogName(), s);
		    	write(defaultLogFile, s , false);
			} catch (IOException e1) {				
					e1.printStackTrace(); 
				}
		}
        
        public static void write_to_log_new_line(String s) throws Exception{
		    try {
				//write(defaultLogFile+ InputsReader.getLogName(), s);
		    	write(defaultLogFile, s, true);
			} catch (IOException e1) {				
					e1.printStackTrace(); 
				}
		}
        
   
        private static void write(String f, String s, boolean newLine) throws IOException {
	    	Calendar calendar = Calendar.getInstance();
	    	SimpleDateFormat dataFormat = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
	    	String currentTime = dataFormat.format((calendar.getTime()));
	        FileWriter aWriter = new FileWriter(f, true);
	        if(newLine)
	           aWriter.write(" " + s + "\n");
	        else
	        	aWriter.write(currentTime + " " + s );
	        aWriter.flush();
	        aWriter.close();
        }
    }

